package com.ch.web.controller;

import com.ch.web.entity.XyDzEntity;
import com.ch.web.service.XyDzService;
import com.ch.web.utils.PageUtils;
import com.ch.web.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

/**
 *
 *
 * @author chenHao
 * @email 1429542285@qq.com
 * @date 2022-10-20 14:14:44
 */
@RestController
@RequestMapping("xy/dz")
public class XyDzController {
    @Autowired
    private XyDzService xyDzService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = xyDzService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{talkId}")

    public R info(@PathVariable("talkId") Long talkId){
		XyDzEntity xyDz = xyDzService.getById(talkId);

        return R.ok().put("xyDz", xyDz);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody XyDzEntity xyDz){
		xyDzService.save(xyDz);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody XyDzEntity xyDz){
		xyDzService.updateById(xyDz);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] talkIds){
		xyDzService.removeByIds(Arrays.asList(talkIds));

        return R.ok();
    }

    /**
     * 点赞
     */
    @PostMapping("/like")
    public R dz(@RequestBody XyDzEntity xyDzEntity, HttpServletRequest request){
       return xyDzService.dzTalk(xyDzEntity,request)?R.ok():R.error();
    }
    /**
     * 取消点赞
     */
    @PostMapping("cancelDz")
    public R cancelDz(@RequestBody XyDzEntity xyDzEntity, HttpServletRequest request){
        return R.okOrError(xyDzService.cancelDz(xyDzEntity,request));
    }
}
